#include <stdio.h>
#include <stdlib.h>
#include <error.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>

#define PORT 8888
#define MAXDATESIZE 100 //每次最大数据传输量

int main(int argc, char *argv[])
{
     int socketfd, recvbytes;
     char buf[MAXDATESIZE];
     struct hostent *host;
     struct sockaddr_in serv_addr;
     host = gethostbyname("127.0.0.1");
     if((socketfd = socket(AF_INET,SOCK_STREAM,0)) == -1)
     {
	  perror("socket创建出错");
	  exit(1);
	  
     }
     serv_addr.sin_family = AF_INET;
     serv_addr.sin_port = htons(PORT);
     serv_addr.sin_addr = *((struct in_addr*)host->h_addr);
     bzero(&(serv_addr.sin_zero),8);
     if(connect(socketfd,(struct sockaddr*)&serv_addr,sizeof(struct sockaddr)) == -1)
     {
	  perror("connect出错!");
	  exit(1);
	  
     }
     
     if((recvbytes = recv(socketfd,buf,MAXDATESIZE,0)) == -1)
     {
	  perror("recv error!");
	  exit(1);
	  
     }
     buf[recvbytes] = '\0';
     printf("Received:%s",buf);
     clese(socketfd);
     
    return 0;
}

